package org.blame.rabbitmqadvancedfeature.config;


import org.blame.rabbitmqadvancedfeature.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
public class DelConfig {

    @Bean("normalQueue")
    public Queue normalQueue(){
        return QueueBuilder.durable(Constants.NORMAL_QUEUE)
                .ttl(10000)
                .deadLetterExchange(Constants.DEL_EXCHANGE)
                .deadLetterRoutingKey("del")
//                .maxLength(10L)
                .build();
    }

    @Bean("normalExchange")
    public DirectExchange normalExchange(){
        return ExchangeBuilder.directExchange(Constants.NORMAL_EXCHANGE).build();
    }

    @Bean("normalBlinding")
    public Binding normalBlinding(@Qualifier("normalQueue") Queue queue,
                                  @Qualifier("normalExchange") DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("normal");
    }

    @Bean("delQueue")
    public Queue delQueue(){
        return QueueBuilder.durable(Constants.DEL_QUEUE).build();
    }

    @Bean("delExchange")
    public DirectExchange delExchange(){
        return ExchangeBuilder.directExchange(Constants.DEL_EXCHANGE).build();
    }

    @Bean("delBlinding")
    public Binding delBlinding(@Qualifier("delQueue") Queue queue,
                                  @Qualifier("delExchange") DirectExchange directExchange){
        return BindingBuilder.bind(queue).to(directExchange).with("del");
    }

}
